#include <stdio.h>
#include <limits.h>

static const int maxLen = 1E6+5;
int arr[maxLen];
int n;

int myStk[maxLen];
int leftMin[maxLen];
int rightMin[maxLen];
int curTop = 1, topLow;

int main() 
{
    scanf("%d", &n);
    //数组里垫一个最小值兜底，省去额外判断
    arr[0] = INT_MIN;
    //对加入栈的数字，进行左右最近较小值评估，记录入栈的下标
    //由于0位置有个兜底值，所以入栈的下标为实际下标 + 1
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d", &arr[i]);
        topLow = curTop - 1;
        while(arr[i] <= arr[myStk[topLow]])
        {
            rightMin[myStk[topLow]] = i;
            leftMin[myStk[topLow]] = myStk[topLow - 1];
            curTop--;
            topLow--;
        }
        myStk[curTop] = i;
        curTop++;
    }
    //评估并清空栈内剩余元素
    while(curTop > 1)
    {
        topLow = curTop - 1;
        rightMin[myStk[topLow]] = 0;
        leftMin[myStk[topLow]] = myStk[topLow - 1];
        --curTop;
    }
    //倒序遍历，纠正重复值的情况
    for(int i = n; i > 0 ; --i)
    {
        if(arr[rightMin[i]] == arr[i])
        {
            rightMin[i] = rightMin[rightMin[i]];
        }
    }
    for(int i = 1; i <= n; ++i)
    {
        printf("%d %d\n", leftMin[i] - 1, rightMin[i] - 1);
    }
    return 0;
}